package com.zh.note.huawei.onehundred.分糖果;

import java.util.Scanner;

/**
 * @Author: zhanghuan
 * @date: 2023/9/2 09:24
 * @description: create it
 */
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        int res = candy(n);
        System.out.println(res);
    }

    private static int dfs(int n) {

        if (n == 1) {
            return 0;
        }
        int res = 0;
        if (n % 2 != 0) {
            // 不能均分，考虑n+1和n-1的最小值
            res += Math.min(dfs(n + 1), dfs(n - 1)) + 1;
        } else {
            // 可以均分
            res += dfs(n / 2) + 1;
        }
        return res;
    }

    public static int candy(int n) {
        int count = 0;
        // 2 count = 1 2/2 = 1 count =2
        for (int i = n; i != 1; i /= 2, count++) {
            if (n == 3) {
                return count += 2;
            }
            if (i % 2 != 0) {
                if ((i + 1) / 2 % 2 == 0)
                    i++;
                else
                    i--;
                count++;
            }
        }
        return count;
    }
}
